package fractal;

import entity.Position;
import astar.IAstarMap;

public class BiomeMap implements IAstarMap
{
	protected TerrainBiome[][] _Map;

	public BiomeMap(int pTaille)
	{
		init( pTaille );
	}

	public BiomeMap(TerrainMap pTerrainMap)
	{
		int size = pTerrainMap._Map.length;
		_Map = new TerrainBiome[size][size];
		for ( int i = 0; i < size; i++ )
		{
			for ( int j = 0; j < size; j++ )
			{
				_Map[i][j] = new TerrainBiome( pTerrainMap._Map[i][j] );
			}
		}
	}

	protected void init( int pTaille )
	{
		_Map = new TerrainBiome[pTaille][pTaille];
		for ( int i = 0; i < pTaille; i++ )
		{
			for ( int j = 0; j < pTaille; j++ )
			{
				_Map[i][j] = new TerrainBiome();
			}
		}
	}

	public TerrainBiome[][] getMap()
	{
		return _Map;
	}

	@Override
	public double getValue( Position pPos )
	{
		TerrainBiome biome = _Map[pPos.getX()][pPos.getY()];
		
		if( BiomeType.SEA.equals(  biome.getBiomeType()) )
		{
			return 0;
		}
		if( BiomeType.OCEAN.equals(  biome.getBiomeType()) )
		{
			return 0;
		}
		if( biome.getRiver() )
		{
			return 0;
		}
		return biome.getHeight();
	}

	@Override
	public boolean isBlocked( Position pPos )
	{
		return pPos.getX() == -1 || pPos.getY() == -1 || pPos.getX() == _Map.length - 1 || pPos.getY() == _Map.length - 1;
	}
}
